#pragma once

#include <cmath>
#include <math/round.h>

namespace My {

class Control;

COLORREF MeanColor(COLORREF c1, COLORREF c2);
COLORREF MeanSysColor(int c1, int c2);

/// Alignment constants
enum {
	ALIGN_HNONE		= 0x00,
	ALIGN_HLEFT		= 0x01,
	ALIGN_HRIGHT	= 0x02,
	ALIGN_HCENTER	= 0x03,
	ALIGN_HSTRETCH	= 0x04,
	ALIGN_HMASK		= 0x0F,
	ALIGN_VNONE		= 0x00,
	ALIGN_VTOP		= 0x10,
	ALIGN_VBOTTOM	= 0x20,
	ALIGN_VCENTER	= 0x30,
	ALIGN_VSTRETCH	= 0x40,
	ALIGN_VMASK		= 0xF0,
	ALIGN_NONE		= 0,
	ALIGN_CENTER	= ALIGN_HCENTER|ALIGN_VCENTER,
	ALIGN_STRETCH	= ALIGN_HSTRETCH|ALIGN_VSTRETCH
};

CRect AlignRect(const CRect & r0, CRect r, int align);

CRect AlignRect(const CRect & r, const CPoint & p, int align);

class SaveObjects {
private:
	CDC *		m_pDC;
	CPen *		m_pPen;
	CBrush *	m_pBrush;
	CFont *		m_pFont;
public:
	SaveObjects(CDC * pDC);
	~SaveObjects();
public:
	const CPen * GetPen() const
		{ return m_pPen; }
	const CBrush * GetBrush() const
		{ return m_pBrush; }
	const CFont * GetFont() const
		{ return m_pFont; }
};

class ClientDC : public CClientDC {
private:
	CPoint	m_Org;
public:
	ClientDC(Control * pControl);
	~ClientDC();
};

class ClipRect {
private:
	CDC *	m_pDC;
	CRgn	m_Old;
public:
	ClipRect(Control * pOwner, CDC * pDC, const CRect & r, bool enabled = true);
	~ClipRect();
};

void Draw3dRect(CDC * pDC, const CRect & r, COLORREF cTL, COLORREF cBR);

///draws horizontal line by setting every other pixel to given color
void DrawAlternateHorizLine(CDC * pDC, int y, int x1, int x2, COLORREF c);

///draws vertical line by xor'ing every other pixel with given color
void XorAlternateVertLine(CDC * pDC, int x, int y1, int y2, COLORREF c);

/// Rounds to nearest
inline int Round(float x)
{
	return (int) floor(x + 0.5f);
}
/// Rounds to nearest
inline int Round(double x)
{
	return (int) floor(x + 0.5);
}

} // My
